package org.jeecg.modules.param.area.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.modules.param.area.entity.BikeSysArea;
import org.jeecg.modules.param.area.entity.BikeSysUserArea;
import org.jeecg.modules.param.area.mapper.BikeSysAreaMapper;
import org.jeecg.modules.param.area.mapper.BikeSysUserAreaMapper;
import org.jeecg.modules.param.area.service.IBikeSysUserAreaService;
import org.jeecg.modules.param.station.entity.BikeStation;
import org.jeecg.modules.param.station.mapper.BikeStationMapper;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description: bike_sys_user_area
 * @Author: 月月鸟
 * @Date:   2021-05-20
 * @Version: V1.0
 */
@Service
public class BikeSysUserAreaServiceImpl extends ServiceImpl<BikeSysUserAreaMapper, BikeSysUserArea> implements IBikeSysUserAreaService {
    @Resource
    private BikeSysUserAreaMapper bikeSysUserAreaMapper;
    @Resource
    private BikeStationMapper bikeStationMapper;
    @Resource
    private BikeSysAreaMapper bikeSysAreaMapper;
    @Override
    public BikeSysUserArea selectOne(LoginUser sysUser) {
        //获取权限数据
        if (sysUser!=null){
            QueryWrapper<BikeSysUserArea> wrapper = new QueryWrapper<>();
            wrapper.eq("user_id",sysUser.getUsername());
            return bikeSysUserAreaMapper.selectOne(wrapper);
        }else {
            return null;
        }
    }
    /**
     * 获取所有区域网点
     * */
    @Override
    public void getAreaUserAll(String userId) {
        List<String> areas = bikeStationMapper.getStationId();
        areas.addAll(bikeSysAreaMapper.getAreaId());
        String areaIds = areas.toString().replace("[", "").replace("]", "").replace(" ","");
        BikeSysUserArea bikeSysUserArea = new BikeSysUserArea();
        bikeSysUserArea.setAreaId(areaIds);
        bikeSysUserArea.setUserId(userId);
        bikeSysUserAreaMapper.insert(bikeSysUserArea);
    }

}
